function [ FileOutput ] = matrixTexTable(tablenumber, data, rowlabels, FileName)

if tablenumber == 4 || tablenumber == 6;

section1 = data(1:3,:);
section2 = data(4:6,:);
section3 = data(7:9,:);

FileOutput = '';
FileOutput = [ FileOutput '\begin{table}[h] \begin{center} \vspace{-1cm}%'];
FileOutput = [ FileOutput sprintf('\n')  ];
    if tablenumber == 4;
        FileOutput = [ FileOutput '\caption{\textbf{Response to Monetary Policy Shock}}\label{350_mu}'];
    else
        FileOutput = [ FileOutput '\caption{\textbf{Response to Monetary Policy Shock ($\phi_{\pi} = 2.5$)}}\label{350_mu_phipi}'];
    end
FileOutput = [ FileOutput sprintf('\n')  ];
FileOutput = [ FileOutput '\vspace{7pt}' ];
FileOutput = [ FileOutput sprintf('\n')  ];
FileOutput = [ FileOutput '\begin{center}'];
FileOutput = [ FileOutput sprintf('\n')  ];
FileOutput = [ FileOutput sprintf('\n')  ];
FileOutput = [ FileOutput '\setstretch{1.1}'];
FileOutput = [ FileOutput sprintf('\n')  ];
FileOutput = [ FileOutput sprintf('\n')  ];
FileOutput = [ FileOutput '\begin{footnotesize}'];
FileOutput = [ FileOutput sprintf('\n')  ];

FileOutput = [ FileOutput sprintf('\\begin{tabular}') ];
FileOutput = [ FileOutput '{'  ];
FileOutput = [ FileOutput 'lc D{.}{.}{3.5}D{.}{.}{3.5}D{.}{.}{3.5}D{.}{.}{3.5}D{.}{.}{3.5}D{.}{.}{3.5}'];
FileOutput = [ FileOutput sprintf('}\n')  ];
FileOutput = [ FileOutput '\toprule[1.5pt]\addlinespace[1mm]'];
FileOutput = [ FileOutput sprintf('\n')  ];
FileOutput = [ FileOutput sprintf('\n')  ];
FileOutput = [ FileOutput sprintf('\n')  ];
FileOutput = [ FileOutput '       &       & \multicolumn{1}{c}{341 Sectors}     & \multicolumn{1}{c}{56 Sectors}     & \multicolumn{1}{c}{7 Sectors}       \\'];
FileOutput = [ FileOutput sprintf('\n')  ];
FileOutput = [ FileOutput sprintf('\n')  ];
FileOutput = [ FileOutput '\hline\addlinespace[1mm]'];
FileOutput = [ FileOutput sprintf('\n')  ];
FileOutput = [ FileOutput sprintf('\n')  ];
FileOutput = [ FileOutput '                 &       & \multicolumn{3}{c}{\textbf{Panel A. Consumption}} \\[+2mm]'];
FileOutput = [ FileOutput sprintf('\n')];
FileOutput = [ FileOutput sprintf('\n')];


%Table contents for the first section of data
lable_dims   = size( rowlabels );
mdims1        = size( section1  );

    for rowctr = 1:lable_dims(1)
        FileOutput = [ FileOutput sprintf('%s', rowlabels{rowctr})];
        FileOutput = [ FileOutput ' &       & '];
        for cctr = 1:mdims1(2)
            FileOutput =  [  FileOutput ...
                                sprintf('%.2f',section1(rowctr,cctr))];
            if( cctr<mdims1(2) )
                FileOutput = [ FileOutput ' & '];
            end
        end
        FileOutput = [ FileOutput sprintf(' \\\\')];
        FileOutput = [ FileOutput sprintf('[+1mm] \n')];
        if( rowctr<lable_dims(1))
            FileOutput = [ FileOutput sprintf('\n')  ];
        end
    end
    
FileOutput = [ FileOutput '                 &       &       &       &       &       &       &  \\'];
FileOutput = [ FileOutput sprintf('\n')];
FileOutput = [ FileOutput sprintf('\n')];
FileOutput = [ FileOutput '                 &       & \multicolumn{3}{c}{\textbf{Panel B. Inflation}} \\[+2mm]   '];
FileOutput = [ FileOutput sprintf('\n')];
FileOutput = [ FileOutput sprintf('\n')];
    
%Table contents for the second section of data
mdims2        = size( section2  );

    for rowctr = 1:lable_dims(1)
        FileOutput = [ FileOutput sprintf('%s', rowlabels{rowctr})];
        FileOutput = [ FileOutput ' &       & '];
        for cctr = 1:mdims2(2)
            FileOutput =  [  FileOutput ...
                                sprintf('%.2f',section2(rowctr,cctr))];
            if( cctr<mdims2(2) )
                FileOutput = [ FileOutput ' & '];
            end
        end
        FileOutput = [ FileOutput sprintf(' \\\\')];
        FileOutput = [ FileOutput sprintf('[+1mm] \n')];
        if( rowctr<lable_dims(1))
            FileOutput = [ FileOutput sprintf('\n')  ];
        end
    end
    
FileOutput = [ FileOutput '                 &       &       &       &       &       &       &  \\'];
FileOutput = [ FileOutput sprintf('\n')];
FileOutput = [ FileOutput sprintf('\n')];
FileOutput = [ FileOutput '                 &       & \multicolumn{3}{c}{\textbf{Panel C. Real Marginal Costs}} \\[+2mm]   '];
FileOutput = [ FileOutput sprintf('\n')];
FileOutput = [ FileOutput sprintf('\n')];
    
%Table contents for the third section of data
mdims3        = size( section3  );

    for rowctr = 1:lable_dims(1)
        FileOutput = [ FileOutput sprintf('%s', rowlabels{rowctr})];
        FileOutput = [ FileOutput ' &       & '];
        for cctr = 1:mdims3(2)
            FileOutput =  [  FileOutput ...
                                sprintf('%.2f',section3(rowctr,cctr))];
            if( cctr<mdims3(2) )
                FileOutput = [ FileOutput ' & '];
            end
        end
        FileOutput = [ FileOutput sprintf(' \\\\')];
        FileOutput = [ FileOutput sprintf('[+1mm] \n')];
        if( rowctr<lable_dims(1))
            FileOutput = [ FileOutput sprintf('\n')  ];
        end
    end

FileOutput = [ FileOutput sprintf('\n')];
FileOutput = [ FileOutput sprintf('\n')];    
FileOutput = [ FileOutput '\addlinespace[1mm] \bottomrule[1.5pt]'];
FileOutput = [ FileOutput sprintf('\n')];
FileOutput = [ FileOutput '\end{tabular}'];
FileOutput = [ FileOutput sprintf('\n')];
FileOutput = [ FileOutput '\end{footnotesize}'];
FileOutput = [ FileOutput sprintf('\n')];
FileOutput = [ FileOutput '\end{center}'];
FileOutput = [ FileOutput sprintf('\n')];
FileOutput = [ FileOutput '\end{table} '];

else tablenumber == 1;
    section1 = data(1,:);
    section2 = data(2,:);

    FileOutput = '';
    FileOutput = [ FileOutput '\begin{table}'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '\begin{center}\vspace{-1cm}%'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '\textbf{\caption{\textbf{Descriptive Statistics}}\label{des_stats}}'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '\vspace{2pt}'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '\vspace{4pt}'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '\setstretch{1.1}'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '\begin{tabular}{l       c       ccccc}'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '\toprule[1.5pt]\addlinespace[1mm]'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '          &       & Mean  & Median & Std & 25\textsuperscript{th} Pct & 75\textsuperscript{th} Pct \\'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '\hline\addlinespace[1mm]'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '          &       &  \multicolumn{5}{c}{\textbf{Panel A. 58 Sector Economy}} \\[+2mm]   '];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput sprintf('\n')];
    
    %Table contents for the first section of data
    lable_dims   = size( rowlabels );
    mdims1        = size( section1  );

    for rowctr = 1:lable_dims(1)
        FileOutput = [ FileOutput sprintf('%s', rowlabels{rowctr})];
        FileOutput = [ FileOutput '   &       & '];
        for cctr = 1:mdims1(2)
            FileOutput =  [  FileOutput ...
                                sprintf('%.2f',section1(rowctr,cctr))];
            if( cctr<mdims1(2) )
                FileOutput = [ FileOutput ' & '];
            end
        end
        FileOutput = [ FileOutput sprintf(' \\\\')];
        FileOutput = [ FileOutput sprintf('\n')];
    end
    
    FileOutput = [ FileOutput '          &       &       &       &       &       &  \\\'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '          &       &  \multicolumn{5}{c}{\textbf{Panel B. 350 Sector Economy}} \\[+2mm]'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput sprintf('\n')];
    
%Table contents for the second section of data
    mdims2        = size( section2  );

    for rowctr = 1:lable_dims(1)
        FileOutput = [ FileOutput sprintf('%s', rowlabels{rowctr})];
        FileOutput = [ FileOutput  '   &       & '];
        for cctr = 1:mdims2(2)
            FileOutput =  [  FileOutput ...
                                sprintf('%.2f',section2(rowctr,cctr))];
            if( cctr<mdims2(2) )
                FileOutput = [ FileOutput ' & '];
            end
        end
        FileOutput = [ FileOutput sprintf(' \\\\')];
    end
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '\addlinespace[1mm]\bottomrule[1.5pt]'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '\end{tabular}'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '%\end{scriptsize}'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '\end{center}'];
    FileOutput = [ FileOutput sprintf('\n')];
    FileOutput = [ FileOutput '\end{table}'];
    FileOutput = [ FileOutput sprintf('\n')];

end

%% Write file out
fid = fopen( [ FileName '.tex' ], 'wt' );
fprintf(fid, '%s', FileOutput );
fclose( fid );

end
    
